<template>
  <div class="side-bar">
    <scroll class="scroll-area" ref="scroll">
      <div class="category-item" 
        :key="index"
        :class="{active: currentIndex === index}" 
        v-for="(item, index) in categoryList"
        @click="itemClick(item, index)">
        <div>{{item.title}}</div>
      </div>
    </scroll>
  </div>
</template>

<script>
import Scroll from 'components/common/scroll/Scroll';

export default {
  components: { 
    Scroll 
  },
  props: {
    categoryList: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  watch: {
    categoryList() {
      this.$nextTick(() => {
        this.$refs.scroll.refresh();
      });
    }
  },
  data() {
    return {
      currentIndex: 0
    }
  },
  methods: {
    itemClick(item, index) {
      this.currentIndex = index;
      const obj = {
        maitKey: item.maitKey,
        miniWallkey: item.miniWallkey,
        index
      };
      this.$emit('sideBarClick', obj);
    }
  }
}
</script>

<style scoped>
.side-bar {
  position: relative;
  height: calc(100vh - 93px);
}

.category-item {
  width: 100px;
  height: 45px;
  line-height: 45px;
  font-size: 14px;
  text-align: center;
  color: #666;
  background-color: #f6f6f6;
}

.category-item.active {
  border-left: 3px solid var(--color-tint);
  font-weight: 700;
  color: var(--color-tint);
  background-color: #fff;
}

.scroll-area {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: hidden;
}
</style>